#include <Windows.h>
#include <extend.h>

extern HANDLE _hInstance;
extern BOOL bTrace;

void DebugN( LPSTR, long );
void VarCopy( PCLIPVAR, PCLIPVAR );
void _Pop( void );

static CLIPVAR aWindows;

//----------------------------------------------------------------------------//

LONG PASCAL _export WndProc( HWND hWnd, WORD wMsg, WORD wParam, LONG lParam )
{
   CLIPVAR oWnd;
   LONG lAt;

   if( wMsg == WM_DESTROY )
      PostQuitMessage( 0 );

   if( wMsg == WM_COMMAND )
      MessageBox( 0, "Command", "ok", MB_ICONINFORMATION );

   if( wMsg == WM_LBUTTONDOWN )
   {
      if( lAt = GetProp( hWnd, "FF" ) )
      {
         _AGet( &aWindows, lAt, 0xFFFF, &oWnd );

         _PutDynSym( _GetDynSym( "LButtonDown" ) );
         _Push( &oWnd );
         _PutLN( HIWORD( lParam ) );
         _PutLN( LOWORD( lParam ) );
         _PutQ( wParam );
         _Send( 3 );
         _Pop();
      }
   }

   return DefWindowProc( hWnd, wMsg, wParam, lParam );
}

//----------------------------------------------------------------------------//

CLIPPER REGISTERCL()
{
   WNDCLASS cls;

   cls.lpszClassName = _parc( 1 );
   cls.style         = _parnl( 2 );
   cls.cbClsExtra    = _parni( 3 );
   cls.cbWndExtra    = _parni( 4 );
   cls.hInstance     = IF( _parnl( 5 ), ( HANDLE ) _parnl( 5 ), _hInstance );
   cls.hIcon         = 0;
   cls.hCursor       = ( HANDLE ) _parnl( 6 );
   cls.hbrBackground = IF( _parnl( 7 ), ( HANDLE ) _parnl( 7 ),
                           ( HANDLE ) ( COLOR_WINDOW + 1 ) );
   cls.lpszMenuName  = _parc( 8 );
   cls.lpfnWndProc   = IF( _parnl( 9 ), ( WNDPROC ) _parnl( 9 ),
                                        ( WNDPROC ) WndProc );

   _retl( RegisterClass( &cls ) );
}

//----------------------------------------------------------------------------//

CLIPPER SETCLASSWO() // RD()    hWnd, nIndex, nValue
{
   _retni( SetClassWord( ( HWND ) _parnl( 1 ), ( int ) _parni( 2 ),
                         _parni( 3 ) ) );
}

//----------------------------------------------------------------------------//

CLIPPER GETMODULEH() //  ANDLE( szModuleName )  --> <hInst>
{
   _retnl( ( LONG ) GetModuleHandle( _parc( 1 ) ) );
}

//----------------------------------------------------------------------------//

CLIPPER WINDOWSFIX()
{
   VarCopy( &aWindows, _param( 1, 0xFFFF ) );
}

//----------------------------------------------------------------------------//
